from applications.extensions import ma
from marshmallow import fields
from applications.common.utils.trans_time import stamp2str


class TarLastestOutSchema(ma.Schema):
    id = fields.Integer()
    name = fields.Str()
    category = fields.Method("get_category")
    time = fields.Method("get_time")
    details = fields.Str()
    create_at = fields.DateTime()
    update_at = fields.DateTime()

    def get_category(self, obj):
        if obj.category != None:
            return obj.category.name
        return None

    def get_time(self,obj):
        if obj.time!=None:
            return stamp2str(obj.time)
        return None
